package com.qiangesoft.jpa.controller;

import com.qiangesoft.jpa.entity.SysUser;
import com.qiangesoft.jpa.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/sys-user")
@RestController
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 新增或者修改
     * @param sysUser
     */
    @PostMapping
    public void save(@RequestBody SysUser sysUser) {
        sysUserService.save(sysUser);
    }

    /**
     * 删除
     * @param id
     */
    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable("id") Long id) {
        sysUserService.deleteById(id);
    }

    /**
     * 单个查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public SysUser findById(@PathVariable("id") Long id) {
        return sysUserService.findById(id);
    }

    /**
     * 查询列表
     * @return
     */
    @GetMapping
    public List<SysUser> findAll() {
        return sysUserService.finaAll();
    }

    /**
     * 分页查询
     * @return
     */
    @GetMapping("/page")
    public Page<SysUser> page(@RequestParam Integer pageNum,
                              @RequestParam Integer pageSize,
                              @RequestParam String nickName) {
        return sysUserService.page(pageNum, pageSize, nickName);
    }

}
